<template>
  <div class="my" v-if="userInfo">
    <div class="info">
      <div class="user">
        <div class="word">
          <h5>{{ userInfo.nickname }}</h5>
          <p>{{ userInfo.intro }}</p>
        </div>
        <div class="avatar">
          <!-- 点击头像跳转到我的资料页面 -->
          <img
            @click="$router.push('/myInfo')"
            :src="baseUrl + userInfo.avatar"
            alt=""
          />
        </div>
      </div>
      <div class="question">
        <div class="item">
          <div class="num">{{ userInfo.submitNum }}</div>
          <div class="type">累计答题</div>
        </div>
        <div class="item">
          <div class="num">{{ userInfo.collectQuestions.length }}</div>
          <div class="type">收藏题目</div>
        </div>
        <div class="item">
          <div class="num">{{ userInfo.errorQuestions.length }}</div>
          <div class="type">我的错题</div>
        </div>
        <div class="item">
          <div class="num">
            {{
              Math.round(
                ((userInfo.submitNum - userInfo.errorNum) /
                  userInfo.submitNum) *
                  100
              )
            }}<span>%</span>
          </div>
          <div class="type">正确率</div>
        </div>
      </div>
    </div>
    <div class="facedata">
      <!-- 点击跳转到修改资料页面 -->
      <van-cell
        title="我的岗位"
        :value="userInfo.position"
        size="large"
        class="post"
        is-link
        title-class="txt"
        value-class="txt"
        @click="$router.push('/editInfo?type=position')"
      >
        <template #icon>
          <i class="iconfont iconicon_mine_gangwei"></i>
        </template>
      </van-cell>
      <div class="data">
        <h5>面经数据</h5>
        <div class="group">
          <div class="item">
            <div class="yesterday">
              昨日阅读<span>+{{ userInfo.shareData.read.yesterday }}</span>
            </div>
            <div class="num">{{ userInfo.shareData.read.total }}</div>
            <p>阅读总数</p>
          </div>
          <div class="item">
            <div class="yesterday">
              昨日获赞<span>+{{ userInfo.shareData.star.yesterday }}</span>
            </div>
            <div class="num">{{ userInfo.shareData.star.total }}</div>
            <p>获赞总数</p>
          </div>
          <div class="item">
            <div class="yesterday">
              昨日新增<span>+{{ userInfo.shareData.comment.yesterday }}</span>
            </div>
            <div class="num">{{ userInfo.shareData.comment.total }}</div>
            <p>评论总数</p>
          </div>
        </div>
      </div>
    </div>
    <van-cell-group class="other">
      <van-cell
        title="我的面经分享"
        :value="userInfo.history.share.length"
        is-link
        class="cell"
      >
        <template #icon>
          <i class="iconfont iconicon_mine_mianjing"></i>
        </template>
      </van-cell>
      <van-cell
        title="我的消息"
        :value="userInfo.systemMessages"
        is-link
        class="cell"
      >
        <template #icon>
          <i class="iconfont iconicon_mine_xiaoxi"></i>
        </template>
      </van-cell>
      <van-cell
        title="收藏的题库"
        :value="userInfo.collectQuestions.length"
        is-link
        class="cell"
      >
        <template #icon>
          <i class="iconfont iconicon_mine_tikushoucang"></i>
        </template>
      </van-cell>
      <van-cell title="收藏的企业" value="21" is-link class="cell">
        <template #icon>
          <i class="iconfont iconicon_mine_qiyeshoucang"></i>
        </template>
      </van-cell>
      <van-cell
        title="我的错题"
        :value="userInfo.errorQuestions.length"
        is-link
        class="cell"
      >
        <template #icon>
          <i class="iconfont iconicon_mine_cuoti"></i>
        </template>
      </van-cell>
      <van-cell title="收藏的面试经验" value="21" is-link class="cell">
        <template #icon>
          <i class="iconfont iconicon_mine_mianjing"></i>
        </template>
      </van-cell>
    </van-cell-group>
  </div>
</template>
<script>
// 导入vuex的辅助函数
import { mapState } from 'vuex'
export default {
  data () {
    return {
      baseUrl: process.env.VUE_APP_BASEURL
    }
  },
  computed: {
    ...mapState(['userInfo'])
  }
}
</script>
<style lang="less" scoped>
.my {
  background: #f7f4f5;
  height: 100vh;
  padding-bottom: 50px;
  .info {
    box-sizing: border-box;
    height: 216px;
    background: linear-gradient(45deg, #ce0031, #b8002c);
    color: #fff;
    padding: 32px 15px 0 15px;
    .user {
      display: flex;
      justify-content: space-between;
      .word {
        h5 {
          font-size: 20px;
          font-family: PingFangSC, PingFangSC-Semibold;
          font-weight: 400;
          line-height: 30px;
          height: 30px;
        }
        p {
          opacity: 0.7;
          font-size: 12px;
          font-family: PingFangSC, PingFangSC-Regular;
          margin-top: 8px;
        }
      }
      .avatar {
        img {
          width: 50px;
          height: 50px;
          opacity: 1;
          border: 3px solid rgba(255, 255, 255, 0.38);
          border-radius: 50%;
          margin-right: 22px;
        }
      }
    }
    .question {
      display: flex;
      margin-top: 28px;
      text-align: center;
      .item {
        flex: 1;
        font-size: 20px;
        .num {
          font-weight: 700;
          span {
            font-size: 12px;
            font-weight: 400;
          }
        }
        .type {
          font-size: 12px;
          opacity: 0.7;
          margin-top: 8px;
        }
      }
    }
  }
  .facedata {
    padding: 0 15px;
    .post {
      padding-top: 15px;
      padding-bottom: 15px;
      border-radius: 8px;
      margin-top: -38px;
    }
    .txt {
      font-size: 14px;
    }
    .iconfont {
      font-size: 20px;
      margin-right: 8px;
    }
    .data {
      margin: 10px 0;
      background-color: #fff;
      padding: 17px 0;
      border-radius: 6px;
      h5 {
        color: #181a39;
        font-size: 14px;
        font-family: PingFangSC, PingFangSC-Semibold;
        font-weight: 600;
        padding-left: 15px;
      }
      .group {
        display: flex;
        text-align: center;
        font-size: 10px;
        margin-top: 18px;
        .item {
          flex: 1;
          .yesterday {
            color: #b4b4bd;
            span {
              color: @color;
            }
          }
          .num {
            font-size: 20px;
            color: #181a39;
            font-weight: 700;
            margin: 8px 0 5px 0;
          }
          p {
            color: #545671;
            font-size: 14px;
          }
        }
      }
    }
  }
  .other {
    margin: 0 15px;
    .cell {
      .iconfont {
        font-size: 20px;
        margin-right: 8px;
      }
    }
  }
}
</style>
